package com.java.cloud.controller;

import com.java.cloud.service.SysTerminalManagerService;
import com.java.cloud.service.SysTerminalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.ir.Terminal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//import com.joyoung.cloud.moudles.autosell.entity.SysTerminal;

@Api(tags = "终端基础信息")
@Controller
@RequestMapping("/sysTerminal")
public class SysTerminalController{

    @Autowired
    private SysTerminalService service;

    @Autowired
    private SysTerminalManagerService sysTerminalManagerService;

    /**
       * @return
       * @Description将id带进去
       * @author Fu Hao on 2019/10/15 0015 下午 4:29
    */
    @ApiOperation(value = "终端基础信息查询")
    @GetMapping("/findTerminal")
    @ResponseBody
    public List findTerminal(@RequestParam("id") String id){
        if (!id.isEmpty()){
            System.out.println(service.findTerminal(id));

            return service.findTerminal(id);
        }
        return null;
    }

    /**
       * No such property: code for class: Script1 description
       * @return
       * @Description 终端地图坐标查询
       * @author Fu Hao on 2019/10/16 0016 上午 10:48
    */
    @ApiOperation(value = "终端坐标修改")
    @PostMapping("/updateMap")
    @ResponseBody
    public int updateMap(@RequestParam("id")String id
                            ,@RequestParam("longitude")String longitude
                            ,@RequestParam("latitude")String latitude){
        if (id.isEmpty()||longitude.isEmpty()||latitude.isEmpty()){
            return 001;
        }
       return service.updateMap(id,longitude,latitude);

    }

    /**
     * No such property: code for class: Script1 description
     * @return
     * @Description 终端店主信息删除
     * @author Fu Hao on 2019/10/16 0016 上午 9:29
     */
    @ApiOperation(value = "终端店主信息删除")
    @DeleteMapping("/delTerminalById")
    public int delTerminalById(@RequestParam("id") String id){
        if (id.isEmpty()){
            return 001;
        }
       return sysTerminalManagerService.delTerminalById(id);

    }

    /**
       * No such property: code for class: Script1 description
       * @return
       * @Description 终端店主信息修改 id：终端表id  userName：用户名  phone：用户电话
       * @author Fu Hao on 2019/10/17 0017 下午 1:20
    */
    @ApiOperation(value = "终端店主信息修改")
    @RequestMapping("/updTerminalManager")
    public int updTerminalManager(@RequestParam("id") String id
                                 ,@RequestParam("userName") String userName
                                 ,@RequestParam("phone") String phone){
        if (id.isEmpty()||userName.isEmpty()||phone.isEmpty()){
            return 001;
        }
        String regexNumber="^[1][3,4,5,7,8][0-9]{9}$";
        String regexName="^[\\u4e00-\\u9fa5]{2,4}$";
        Boolean isEmptyNumber=regexNumber.matches(userName);
        Boolean isEmptyName=regexName.matches(phone);
        if (!isEmptyName||!isEmptyNumber){
            return 002;
        }
       return sysTerminalManagerService.updTerminalManager(id,userName,phone);

    }

    /**
     * No such property: code for class: Script1 description
     * @return
     * @Description 终端基础设备信息插入/添加
     * @author Fu Hao on 2019/10/15 0015 下午 6:14
     */
   /* @ApiOperation(value = "终端基础设备信息插入")
    @PutMapping("/insertTerminal")
    @ResponseBody
    public Result insertTerminal(SysTerminalManager sysTerminalManager){
        if (sysTerminalManager.getUserId().isEmpty()||sysTerminalManager.getSysNumber().isEmpty()||sysTerminalManager.getSysName().isEmpty()){
            return ResultGenerator.genFailResult();
        }
        String regexNumber="^[1][3,4,5,7,8][0-9]{9}$";
        String regexName="^[\\u4e00-\\u9fa5]{2,4}$";
        Boolean isEmptyNumber=regexNumber.matches(sysTerminalManager.getSysNumber());
        Boolean isEmptyName=regexName.matches(sysTerminalManager.getSysName());
        if (!isEmptyName||!isEmptyNumber){
            return ResultGenerator.genFailResult();
        }
        //service.insertTerminal(sysTerminalManager);
        return ResultGenerator.genSuccessResult();

    }*/

    /**
     * 终端基础设备信息插入
     * 终端基础设备信息模块：设备基础信息：接收参数，直接覆盖元数据
     *                   业态信息：
     *                   附件、位置信息：位置信息修改，查询位置信息判断是否为空，如果为空直接插入，如果不为空提示位置信息是否覆盖
     *1、获取请求数据，包括设备基础信息、店主信息、经纬度信息、业态信息
     *
     *
     *2、要插入的数据：设备基础信息修改，
     *               终端类型：多选框
     *
     * @return
     */

    @ApiOperation(value = "终端基础信息保存")
    @PostMapping("/insertTerminal")
    @ResponseBody
   public int insertTerminal(Terminal terminal){
       return service.insertTerminal(terminal);

   }



}